/************
 * @file:根据api_ticket和url通过加密返回所有config数据
 * @ahthor: zhaoyj
 * @usedate:2020-10-16
 ************/
const sign = require("./sign.js");
const base64 = require("js-base64").Base64;
const getticket = require("./ticket.js");
const pubAcc =require('../Config.js')

async function getwxconfig(href) {
	let configData;
	try {
		const ticketData = await getticket();
		console.log("ticketData========" + JSON.stringify(ticketData))
		const decodeHref = base64.decode(href);
		configData = sign(ticketData.ticket, decodeHref);
		configData.appid = pubAcc.appid;
	} catch (err) {
		//打印错误日志
		console.log(err);
		configData = {};
	}
	return configData;
}

module.exports = getwxconfig
